import requests
from bs4 import BeautifulSoup
def getHTMLText(url):
    try:
        r=requests.get(url)
        r.raise_for_status()
        #print(r.status_code)
        r.encoding=r.apparent_encoding
        print("抓取成功!\n")
        return r.text
    except:
        print("\n抓取失败!\n")

        
def fillList(ulist,html):
    try:
        soup = BeautifulSoup(html,"html.parser")
        #print(soup.title.string)
        #print(soup.prettify())
        #print(soup.find_all("p")[2].string[6:])
        #temp = soup.find_all(id="naver")
        #temp = soup.select("#naver")
        #temp = soup.select(".result")[1].string
        temp = soup.select("p")
        print(temp)
    except:
        print("\n分析失败!")

    
def output(data=''):
    print(data)

    
def main():
    ulist=[]
    url = "http://m.ip138.com/ip.asp?ip="
    ipurl = "210.26.0.10"
    urls =url+ipurl
    print(urls,end="\n\n")
    html = getHTMLText(urls)
    fillList(ulist,html)
    #output(html)


main()
